﻿using System;
using System.IO;
using System.Xml;
using System.Configuration;
using System.Web;
using SyCODE.Component.DataFactory;
using System.Collections.Specialized;
using SyCODE.Component.Security;
using SyCODE.Component;
using System.Web.Security;

/// <summary>
/// SyCODE 的摘要说明
/// </summary>
namespace SyCODE.Blog
{
    public class SetModule : IHttpHandler
    {        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
			Ticket ticket = Ticket.Get(FormsAuthentication.FormsCookieName);
            if (Ticket.Authenticate(ticket))
            {
                Updater.Module updater = new SyCODE.Blog.Updater.Module(ticket.Name);
                switch (context.Request.Form["active"])
                {
                    case "0":
                        updater.Add(context.Request.Form["title"], context.Request.Form["display"], context.Request.Form["position"], context.Request.Form["body"], context.Request.Form["ticket"]);
                        break;
                    case "1":
                        updater.Set(context.Request.Form["idx"], context.Request.Form["title"], context.Request.Form["display"], context.Request.Form["position"], context.Request.Form["body"], context.Request.Form["ticket"]);
                        break;
                    case "2":
                        updater.Remove(context.Request.Form["idx"]);
                        break;
                    case "3":
                        updater.MoveUp(context.Request.Form["idx"]);
                        break;
                    case "4":
                        updater.MoveDown(context.Request.Form["idx"]);
                        break;
                }
                updater.Dispose();
            }
            else
            {
                Function.ClientAlert(StringResource.GetField("authfaild"));
            }
        }
    }
}